package com.polaris.live.adapter.gift

import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterGiftHeadBinding
import com.polaris.live.ui.party.widget.seat.bean.GiftSeatBean
import com.polaris.live.utils.image.avatar
import com.polaris.live.utils.image.loadImage

/**
 * GiftHeadAdapter
 *
 * @author Created by 半仙 on 2024/3/4/004 13:38
 */
class GiftHeadAdapter : BaseBindingAdapter<AdapterGiftHeadBinding, GiftSeatBean>() {
    private var mHomeOwner: Long? = -1//房主id
    override fun convert(holder: VBViewHolder<AdapterGiftHeadBinding>, item: GiftSeatBean) {
        holder.vb.apply {
            val user = item.seatBean.userBasicVo ?: return
            Glide.with(context).loadImage(user.avatar).transform(CircleCrop()).avatar().into(avatar)
            if (mHomeOwner == user.userId) {
                ivHomeOwner.visibility = View.VISIBLE
                tvSeatId.visibility = View.GONE
            } else {
                tvSeatId.visibility = View.VISIBLE
                ivHomeOwner.visibility = View.GONE
            }
            tvSeatId.text = "${item.seatBean.seatId + 1}"

            if (item.isSelect) {
                llFlag.setBackgroundResource(R.drawable.oval_43c158)
                avatar.setBackgroundResource(R.drawable.oval_stroke_back_43c158)
                tvSeatId.setTextColor(ColorUtils.getColor(R.color.commonButtomTextColor))
            } else {
                llFlag.setBackgroundResource(R.drawable.oval_back_a7a8ad)
                avatar.setBackgroundResource(R.drawable.oval_stroke_back_a7a8ad)
                tvSeatId.setTextColor(ColorUtils.getColor(R.color.white))
            }
        }
    }

    fun setHomeOwner(homeOwnerId: Long) {
        mHomeOwner = homeOwnerId
        notifyDataSetChanged()
    }

    //获取所有选中的用户，并返回他们的id
    fun getSelectUser() = data.filter { it.isSelect }.mapNotNull { it.seatBean.userBasicVo?.userId }

    //获取所有选中的用户
    fun getSelectUserBasic() = data.filter { it.isSelect }.mapNotNull { it.seatBean.userBasicVo }
}